Skip to content

Add lintrunner pre-commit hook#18689

Open
abhinaykukkadapu wants to merge 1 commit intopytorch:mainfrom
abhinaykukkadapu:lintrunner-pre-commit-hook
Open

Add lintrunner pre-commit hook#18689
abhinaykukkadapu wants to merge 1 commit intopytorch:mainfrom
abhinaykukkadapu:lintrunner-pre-commit-hook

Conversation

@abhinaykukkadapu
Copy link
Copy Markdown
Contributor

@abhinaykukkadapu abhinaykukkadapu commented Apr 3, 2026

Add lintrunner pre-commit hook

Summary:
Run lintrunner automatically on every commit via .githooks/pre-commit.
Hooks are enabled by default through install_executorch.sh.

Test Plan:

  • lintrunner not installed: warns and skips
  • .lintrunner.toml missing: warns and skips
  • First init (no hash stored): runs lintrunner init, stores hash
  • Second commit (toml unchanged): skips init
  • .lintrunner.toml modified: re-runs init
  • lintrunner init fails: blocks commit
  • First commit (no HEAD^): runs without error
  • Clean file: lint passes, commit succeeds
  • Lint violation: lint fails, commit blocked
  • sha256sum/shasum produce same hash

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Apr 3, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/18689

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Pending, 2 Unrelated Failures

As of commit efc82a5 with merge base 19bbeac (image):

NEW FAILURE - The following job has failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@GregoryComer
Copy link
Copy Markdown
Member

I don't personally love commit hooks, as they can slow down iteration - esp. since lint w/ mypy can take a long time. I'm not opposed to landing it, but can we add a persistent local opt-out mechanism?

revision_flag=""
fi

lintrunner -a $revision_flag --skip MYPY
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me why skip MYPY?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is taking too much time and every time if the developer amends the commit, it might annoy them.

cd -- "$( realpath "$( dirname -- "${BASH_SOURCE[0]}" )" )" &> /dev/null || /bin/true
./run_python_script.sh ./install_executorch.py "$@"

# Install git hooks if inside a git repo
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if someone else (IIRC Arm) installs their own pre-commit hooks, would it collide with that?

Also Arm has more scripts here for push etc - https://github.com/pytorch/executorch/tree/19bbeac41ab4ba21aa95a44d464e72b8da571302/backends/arm/scripts

We should consolidate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@digantdesai good point, it seems their pre-commit hook is a subset of what we are doing and pre-push hook is very arm specific, i think we can consolidate the pre-commit but pre-push we should leave it as-is, because it has some sign-off checks, commit format etc which might surprise others.

What i will do is we can let the installation via install_executorch take precedence per hook, and honor the backend's own hooks via thin wrapper and call them if installed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also CC arm POCs if needed as fyi.

@abhinaykukkadapu
Copy link
Copy Markdown
Contributor Author

abhinaykukkadapu commented Apr 6, 2026

I don't personally love commit hooks, as they can slow down iteration - esp. since lint w/ mypy can take a long time. I'm not opposed to landing it, but can we add a persistent local opt-out mechanism?

I disabled mypy for this reason and now it is pretty fast. I think the tradeoff is better than another loop of review -> lint fix -> review?

Also, you can also bypass git commit hooks using --no-verify flag.

@abhinaykukkadapu abhinaykukkadapu force-pushed the lintrunner-pre-commit-hook branch from 93af227 to 335f19b Compare April 6, 2026 23:46
Summary:
Run lintrunner automatically on every commit via .githooks/pre-commit.
Hooks are enabled by default through install_executorch.sh using
core.hooksPath. Add a pre-push passthrough that delegates to
.git/hooks/pre-push so backend-specific hooks (e.g., ARM) still work.
Remove redundant ARM pre-commit hook.

Test Plan:
Tested all pre-commit branches (lintrunner missing, toml missing,
first init, hash match, toml changed, init failure, first commit,
lint pass, lint fail, sha256sum/shasum parity) — 18/18 passed.
@abhinaykukkadapu abhinaykukkadapu force-pushed the lintrunner-pre-commit-hook branch from 335f19b to efc82a5 Compare April 7, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streamline Internal and External CI to ease qualcomm development workflow

3 participants